﻿using NUnit.Framework;
using EventHandler.Libraries.Business.Security;
using EventHandler.Libraries.Business.Database;
using System;
using Rhino.Mocks;
using System.Data;

namespace EventHandler.Libraries.Business.Tests.Security.AccountTests
{
	[TestFixture]
	public class DeleteAccountTests
	{
		[Test]
		public void DeleteAccount_Should_Succeed_On_Existing_Account()
		{
			int testAccountId = 9999;

			IDatabaseHelper dbHelper = AccountTestUtilities.CreateDatabaseHelper();
			IAccountHelper helper = new AccountHelper(dbHelper);

			var cnn = MockRepository.GenerateMock<IDbConnection>();
			dbHelper.Expect(x => dbHelper.GetConnection()).Return(cnn);

			var cmd = MockUtilities.CreateMockCommand(cnn);
			var paramAccountId = MockUtilities.CreateMockParameter(cmd);
			
			helper.DeleteAccount(testAccountId);

			cnn.AssertWasCalled(x => x.Open());
			cnn.AssertWasCalled(x => x.Close());
			cmd.AssertWasCalled(x => x.ExecuteNonQuery());

			Assert.AreEqual("Auth.DeleteAccount", cmd.CommandText);
			Assert.AreEqual(CommandType.StoredProcedure, cmd.CommandType);

			Assert.AreEqual("@AccountID", paramAccountId.ParameterName);
			Assert.AreEqual(testAccountId, paramAccountId.Value);
			Assert.AreEqual(DbType.Int32, paramAccountId.DbType);
		}
	}
}
